#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e4 + 10, INF = 0x3f3f3f3f;

int n, m;
vector<pair<int, int>> g[N];
vector<int> ask;
int ans[N], del[N];

int rt, mxsiz, tot, siz[N];
int getrt(int x, int fa)
{
    siz[x] = 1;
    int tmp = 0;
    for (auto [y, _] : g[x]) {
        if (y == fa || del[y]) continue;
        siz[x] += getrt(y, x);
        tmp = max(tmp, siz[y]);
    }
    tmp = max(tmp, tot - siz[x]);
    if (tmp < mxsiz) mxsiz = tmp, rt = x;
    return siz[x];
}

ll dis[N], tt;
void getdis(int x, int fa, ll d) {
    dis[++tt] = d;
    for (auto [y, w] : g[x]) {
        if (y == fa || del[y]) continue;
        getdis(y, x, d + w);
    }
}

unordered_set<ll> s;
void calc(int x)
{
    s.clear();s.insert(0);
    for (auto [y, w] : g[x]) {
        if (del[y]) continue;
        tt = 0;getdis(y, x, w);
        for (int i = 1;i <= tt;i++)
            for (int j = 1;j <= m;j++)
                if (ask[j] >= dis[i]) ans[j] |= s.count(ask[j] - dis[i]);

        for (int i = 1;i <= tt;i++)
            s.insert(dis[i]);
    }
}

void dfs(int x)
{
    del[x] = 1;calc(x);
    for (auto [y, _] : g[x]) {
        if (del[y]) continue;
        mxsiz = tot = siz[y];
        getrt(y, x); dfs(rt);
    }
}

void solve()
{
    cin >> n >> m;
    for (int i = 1;i < n;i++) {
        int u, v, w;cin >> u >> v >> w;
        g[u].push_back({ v,w });
        g[v].push_back({ u,w });
    }
    ask.push_back(0);
    for (int i = 1;i <= m;i++) {
        int k; cin >> k;
        ask.push_back(k);
    }

    mxsiz = tot = n;
    getrt(1, 0);
    dfs(rt);

    for (int i = 1;i <= m;i++) puts(ans[i] ? "AYE" : "NAY");
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}